package com.zeng.sim.controller.domain.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zeng.sim.controller.domain.base.BaseDomain;
import lombok.Getter;
import lombok.Setter;

/**
 * 前端表格数据封装
 */
@Getter
@Setter
public class ResultTable extends BaseDomain {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 提示消息
     */
    private String msg;

    /**
     * 消息总量
     */
    private Long count;

    /**
     * 数据对象
     */
    private Object data;

    /**
     * 构 建
     */
    public static ResultTable pageTable(long count, Object data) {
        ResultTable resultTable = new ResultTable();
        resultTable.setData(data);
        resultTable.setCode(0);
        resultTable.setCount(count);
        return resultTable;
    }

    public static ResultTable dataTable(Object data) {
        ResultTable resultTable = new ResultTable();
        resultTable.setData(data);
        resultTable.setCode(0);
        return resultTable;
    }

    public static ResultTable pageTable(IPage page) {
        ResultTable resultTable = new ResultTable();
        resultTable.setData(page.getRecords());
        resultTable.setCode(0);
        resultTable.setCount(page.getTotal());
        return resultTable;
    }

}
